
from sqlalchemy import Column, Integer, String, Text
from app.entity.baseModal import BaseModal
from sqlalchemy.orm import Mapped,mapped_column,declarative_base, relationship,sessionmaker

from app.entity.projectUser import ProjectUser
from app.entity.user import User

class Project(BaseModal):
    __tablename__="jz_project"
    _soft_delete = True 
    _fieldIgnore = []
    name:Mapped[str]=mapped_column(String(100))
    remask:Mapped[str]=mapped_column(String(255))
    createBy:Mapped[int]=mapped_column(Integer,name="created_by")
    status:Mapped[str]=mapped_column(String(10))

    def getCreator(self)->User:
        user=self.getSession().query(User).filter_by(id=self.createBy).with_entities(User.nickname).one()
        return user
    
    def getProjectPeopleCount(self):
        return self.getSession().query(ProjectUser).where(ProjectUser.projectId==self.id).count()
    
    def getProjectUsersAttr(self):
        return self.getSession().query(ProjectUser).where(ProjectUser.projectId==self.id).all()